package main;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SessionManager
{
	private static ThreadLocal request = new ThreadLocal();

	private static ThreadLocal response = new ThreadLocal();

	public static void setContext(HttpServletRequest req,
			HttpServletResponse resp)
	{
		request.set(req);
		response.set(resp);
	}

	public static HttpServletRequest getRequest()
	{
		return (HttpServletRequest) request.get();
	}

	public static HttpServletResponse getResponse()
	{
		return (HttpServletResponse) response.get();
	}

	public static HttpSession getSession()
	{
		try
		{
			if (getRequest() == null)
				return null;
			else
				return getRequest().getSession();

		} catch (RuntimeException e)
		{
			return null;
		}
	}
}
